package com.alexsh.dao.impl;

import com.alexsh.dao.DataLoader;
import com.alexsh.domain.Book;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @author Alexander Shmygin <AShmygin@luxoft.com>
 * @version 1.0
 */
public class BooksRepository implements Serializable {

    private static final long serialVersionUID = -1736025011512789439L;

    private HashMap<String, Book> books;

    private DataLoader dataLoader;

    private BooksRepository() {
        this.books = setBooks();
    }

    private HashMap<String, Book> setBooks() {
        dataLoader = getLoader();
        return dataLoader.getData();
    }

    private CsvFileLoader getLoader() {
        return new CsvFileLoader();
    }

    public HashMap<String, Book> getBooks() {
        return this.books;
    }

    public void addBook(Book book) {
        this.books.put(book.getId(), book);
    }

    public void deleteBookById(String bookId) {
        this.books.remove(bookId);
    }
}
